package com.woniuxy.cloud.userassembly.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;


import org.springframework.boot.autoconfigure.amqp.RabbitTemplateConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {
    public static final String RECORD_FINISH_EXCHANGE="exchange.record.finish";
    public static final String RECORD_FINISH_QUEUE="queue.record.finish";
    public static final String RECORD_FINISH_RK="record.finish";

    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange(RECORD_FINISH_EXCHANGE);
    }
    @Bean
    public Queue queue(){
        return new Queue(RECORD_FINISH_QUEUE);
    }

    @Bean
    public Binding binding(){
        return BindingBuilder.bind(queue()).to(topicExchange()).with(RECORD_FINISH_RK);
    }

    @Bean
    public RabbitTemplate rabbitTemplate(RabbitTemplateConfigurer configurer, ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate();
        configurer.configure(template, connectionFactory);
        //使用json序列化对象
        template.setMessageConverter(new Jackson2JsonMessageConverter());
        return template;
    }


}
